<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  function f(s) {
    const map = {};
    let left = 0;

    return s.split('').reduce((max, v, i) => {
      left = map[v] >= left ? map[v] + 1 : left;
      map[v] = i;
      return Math.max(max, i - left + 1);
    }, 0);
  }

  console.log(f('abcabcbb'));
</script>
</body>
</html>